/******************************************************************************
 * Filename : uc_file.h
 * Created  : 2009-10-01 by franco.yin
 * Description -
 *
 ******************************************************************************/

#ifndef	__UC_FILE_H__
#define	__UC_FILE_H__

#ifdef __cplusplus
extern "C" {
#endif

#include "uc_public.h"
#include "uc_time.h"
#include "uc_func.h"
#include "uc_list.h"

#define UCFILE_DIR_FILE_MAX	3000

enum ucfile_get_dir_ret{
	UCFILE_DIR_OK = OK,
	UCFILE_DIR_BREAK,
	UCFILE_DIR_DROP = 7788,

	UCFILE_DIR_MAX
};

typedef struct _ucfile_dir {
	ucnode_s node;
	char is_folder;
	char name[UC_BUF_PATH_LEN];
	char full_path[UC_BUF_PATH_LEN];
	uctime_sec_s creat_time;
} ucfile_dir_s;

extern char *ucfile_pwd();
extern int ucfile_exist(char *fname);
extern int ucfile_size(const char *fname);
extern UC_S64 ucfile_size_big(const char *fname);
extern int ucfile_cp(char *src, char *dst);
extern int ucfile_log_file_rebuild(const char *fname, int max_len);
extern int ucfile_log_file_rebuild_keep_tail(const char *fname, int max_len, int keep_line);
extern void ucfile_init();
extern char *ucfile_get_exe_full_path();
extern char *ucfile_get_exe_path();
extern char *ucfile_get_exe_file();
extern char *ucfile_get_ext(char *src_filename, char *filename, char *extname);
extern int ucfile_dir(char *dir_name, int sort_by, int order, char *external_cmd, int count_from, int count_to, uclist_s *pList, int (*pFun)(ucfile_dir_s *, void *, void *, void *), void *p1, void *p2, void *p3);
#define ucfile_get_dir(dir_name, pFun, p1, p2, p3) ucfile_dir(dir_name, 0, 1, NULL, 1, 1000, NULL, pFun, p1, p2, p3)
#define ucfile_get_dir_list(dir_name, pList) ucfile_dir(dir_name, 0, 1, NULL, 1, 1000, pList, NULL, NULL, NULL, NULL)
extern int ucfile_free_dir_list(uclist_s *pList);
extern char *ucfile_rename_repeat(char *folder, char *name, char *new_name);
extern int ucfile_folder_size_k(char *folder);
extern int ucfile_line(char *file, int (*line_one)(char *, void *, void *, void *), void *p1, void *p2, void *p3);
extern int ucfile_append_ext(char *file_name, char *head, int head_len, char *buf, int buf_len);
extern int ucfile_append(char *file_name, char *buf, int len);
extern int ucfile_read_pos(char *file_name, UC_S64 pos, char *buf, int len);
extern int ucfile_write_pos(char *file_name, UC_S64 pos, char *pData, int len, int if_flush, int if_truncate);
extern int ucfile_rlock(char *lock_file);
extern int ucfile_wlock(char *lock_file);
extern void ucfile_unlock(int lock_fd);
extern void ucfile_clean_expired(char *dir_path, int before_days, int folder_max_size_k);

#ifdef __cplusplus
}
#endif

#endif

